package fr.nts.application.novadmin.database.model.employe;

import java.util.Date;
import java.util.List;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;

import fr.nts.application.novadmin.database.model.common.NovadminDocument;
import fr.nts.application.novadmin.database.model.enumeration.NovadminDroit;
import fr.nts.application.novadmin.database.model.enumeration.NovadminPoste;
import fr.nts.application.novadmin.database.model.enumeration.NovadminRole;
import fr.nts.application.novadmin.database.model.enumeration.Sexe;
import fr.nts.application.novadmin.database.model.enumeration.SocieteType;
import fr.nts.framework.database.jpa.model.AJPAModel;

/**
 * Represente les caractéristiques de base d'un utilisateur Novadmin.
 * 
 * @author sco
 * @version 1.0.0
 */
@MappedSuperclass
public abstract class BaseNovadminEmploye extends AJPAModel<Long>{
    
    private static final long serialVersionUID = 1L;
    
    private static final Logger log = LoggerFactory.getLogger(BaseNovadminEmploye.class);
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, length = 10, unique = true)
    private Long id;
    
    @Column(name = "nom", nullable = false, length = 55, unique = true)
    private String nom;
    
    @Column(name = "prenom", nullable = false, length = 55)
    private String prenom;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_naissance", nullable = false)
    private Date dateNaissance;
    
    @Column(name = "adresse1", nullable = true, length = 255)
    private String adresse1;
        
    @Column(name = "adresse2", nullable = true, length = 255)
    private String adresse2;
    
    @Column(name = "code_postal", nullable = true, length = 55)
    private String codePostal;
    
    @Column(name = "ville", nullable = true, length = 55)
    private String ville;
 
    @Column(name = "telephone1", nullable = true, length = 10)
    private String telephone1;
        
    @Column(name = "telephone2", nullable = true, length = 10)
    private String telephone2;
    
    @Column(name = "email_perso", nullable = false, length = 255)
    private String emailPerso;
    
    @Column(name = "numero_secu", nullable = true, length = 13, unique = true)
    private String numeroSecu;
    
    @Column(name = "identifiant_employe", nullable = false, length = 255, unique = true, updatable = false)
    private String identifiantEmployee;
    
    @Lob
    @Column(name = "commentaire", nullable = true)
    private String commentaire;
    
    @Column(name = "salaire", nullable = false)
    private double salaire = 0;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "role", nullable = true)
    private NovadminRole role;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "sexe", nullable = true)
    private Sexe sexe;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "job", nullable = true)
    private NovadminPoste job;

    @Enumerated(EnumType.STRING)
    @Column(name = "societe_type", nullable = false)
    private SocieteType societType;
    
    @Column(name = "societe_name", nullable = true)
    private String societName;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_arrivee", nullable = true)
    private Date dateArrive;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "date_depart", nullable = true)
    private Date dateDepart;
    
    @Column(name = "permis_voiture", nullable = false, length = 1)
    private boolean permisVoiture = false;
    
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "cv_id", nullable = true)
    private NovadminDocument cv;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "droit", nullable = false)
    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "novadmin_employe_droit", joinColumns = @JoinColumn(name = "employe_id"))  
    private List<NovadminDroit> droits = Lists.newArrayList();
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString(){
    	if(getLog().isDebugEnabled()){
	    	return new ToStringBuilder(this).append("id",
	                                                id)
	                                        .append("prenom",
	                                        		prenom)
	                                        .append("dateNaissance",
	                                        		dateNaissance)
	                                        .append("adresse1",
	                                        		adresse1)
	                                        .append("adresse2",
	                                        		adresse2)
	                                        .append("codePostal",
	                                        		codePostal)
	                                        .append("ville",
	                                        		ville)
	                                        .append("telephone1",
	                                        		telephone1)
	                                        .append("telephone2",
	                                        		telephone2)
	                                        .append("emailPerso",
	                                        		emailPerso)
	                                        .append("numeroSecu",
	                                        		numeroSecu)
	                                        .append("identifiantEmployee",
	                                        		identifiantEmployee)
	                                        .append("commentaire",
	                                        		commentaire)
	                                        .append("salaire",
	                                        		salaire)
	                                        .append("role",
	                                        		role)
	                                        .append("sexe",
	                                        		sexe)
	                                        .append("job",
	                                        		job)	
	                                        .append("societType",
	                                        		societType)	
	                                        .append("societName",
	                                        		societName)	
	                                        .append("dateArrive",
	                                        		dateArrive)	
	                                        .append("dateDepart",
	                                        		dateDepart)	
	                                        .append("permisVoiture",
	                                        		permisVoiture)	
	                                        .append("cv",
	                                        		cv == null? null: cv.toString())	
	                                        .append("Nb droit",
	                                        		droits.size())		
	                                        .toString();
    	}else{
    		return super.toString();
    	}
    }


    /*
     * (non-Javadoc)
     * @see fr.nts.framework.database.jpa.model.AJPAObject#getLog()
     */
    @Override
    protected Logger getLog(){
    	return log;
    }
    
    
    // GETTER AND SETTER    
	public Long getId(){
		return id;
	}

	public String getNom(){
		return nom;
	}

	public void setNom(String nom){
		this.nom = nom;
	}

	public String getPrenom(){
		return prenom;
	}

	public void setPrenom(String prenom){
		this.prenom = prenom;
	}

	public Date getDateNaissance(){
		return dateNaissance;
	}

	public void setDateNaissance(Date dateNaissance){
		this.dateNaissance = dateNaissance;
	}

	public String getVille(){
		return ville;
	}

	public void setVille(String ville){
		this.ville = ville;
	}

	public String getIdentifiantEmployee(){
		return identifiantEmployee;
	}

	public void setIdentifiantEmployee(String identifiantEmployee){
		this.identifiantEmployee = identifiantEmployee;
	}

	public String getCommentaire(){
		return commentaire;
	}

	public void setCommentaire(String commentaire){
		this.commentaire = commentaire;
	}

	public double getSalaire(){
		return salaire;
	}

	public void setSalaire(double salaire){
		this.salaire = salaire;
	}

	public NovadminRole getRole(){
		return role;
	}

	public void setRole(NovadminRole role){
		this.role = role;
	}

	public Sexe getSexe(){
		return sexe;
	}

	public void setSexe(Sexe sexe){
		this.sexe = sexe;
	}

	public NovadminPoste getJob(){
		return job;
	}

	public void setJob(NovadminPoste job){
		this.job = job;
	}

	public String getEmailPerso(){
		return emailPerso;
	}

	public void setId(Long id){
		this.id = id;
	}

	public String getAdresse1(){
		return adresse1;
	}

	public void setdress1(String adresse1){
		this.adresse1 = adresse1;
	}

	public String getAdresse2(){
		return adresse2;
	}

	public void setAdresse2(String adresse2){
		this.adresse2 = adresse2;
	}

	public String getCodePostal(){
		return codePostal;
	}

	public void setCodePostal(String codePostal){
		this.codePostal = codePostal;
	}

	public String getTelephone1(){
		return telephone1;
	}

	public void setTelephone1(String telephone1){
		this.telephone1 = telephone1;
	}

	public String getTelephone2(){
		return telephone2;
	}

	public void setTelephone2(String telephone2){
		this.telephone2 = telephone2;
	}

	public void setEmailPerso(String emailPerso){
		this.emailPerso = emailPerso;
	}

	public String getNumeroSecu(){
		return numeroSecu;
	}

	public void setNumeroSecu(String numeroSecu){
		this.numeroSecu = numeroSecu;
	}

	public SocieteType getSocietType(){
		return societType;
	}

	public void setSocietType(SocieteType societType){
		this.societType = societType;
	}

	public String getSocietName(){
		return societName;
	}

	public void setSocietName(String societName){
		this.societName = societName;
	}

	public Date getDateArrive(){
		return dateArrive;
	}

	public void setDateArrive(Date dateArrive){
		this.dateArrive = dateArrive;
	}

	public Date getDateDepart(){
		return dateDepart;
	}

	public void setDateDepart(Date dateDepart){
		this.dateDepart = dateDepart;
	}

	public void setAdresse1(String adresse1){
		this.adresse1 = adresse1;
	}

	public boolean isPermisVoiture(){
		return permisVoiture;
	}

	public void setPermisVoiture(boolean permisVoiture){
		this.permisVoiture = permisVoiture;
	}

	public NovadminDocument getCv(){
		return cv;
	}

	public void setCv(NovadminDocument cv){
		this.cv = cv;
	}

	public List<NovadminDroit> getDroits(){
		return droits;
	}

	public void setDroits(List<NovadminDroit> droits){
		this.droits = droits;
	}
}